package org.poem.controller;

import com.google.gson.Gson;
import org.poem.entity.DemoObject;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/demoAnnoRest")
public class DemoAnnoRestController {

    @ResponseBody
    @RequestMapping("/passEntity")
    public String passEntity(DemoObject demoObject) {
        RequestAttributes ra = RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = ((ServletRequestAttributes) ra).getRequest();
        return "url:" + request.getRequestURI() + " can  assess, DemoObject Json :" + new Gson().toJson(demoObject);
    }
}
